package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ShoppingCartMapper {

    /**
     * 根据用户id 口味和菜品id查询是否存在多个
     *
     * @param shoppingCart
     */
    ShoppingCart selectBY(ShoppingCart shoppingCart);

    /**
     * 新增购物车
     *
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time)" +
            " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void insert(ShoppingCart shoppingCart);
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void update(ShoppingCart cart);


    @Select("select  * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> list(Long currentId);

    /**
     * q清空购物车
     * @param userId
     */
    @Delete("delete  from shopping_cart where user_id = #{userId}")
    void delete(Long userId);
}
